import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:选择排序
 * User:龙宝
 * Date:2023-11-12
 * Time:15:44
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {9,4,1,2,0,6,5,3,10,7,8};
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void selectSort(int[] arr) {
        for(int i = 0;i< arr.length;i++) {
            int max = i;
            for(int j = i+1;j<arr.length;j++) {
                if(arr[max] < arr[j]) {
                    max = j;
                }
            }
            int tmp = arr[i];
            arr[i] = arr[max];
            arr[max] = tmp;
        }
    }
}
